//
//  TabVC.m
//  ZhiBoYuan
//
//  Created by mac on 2018/4/11.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TabVC.h"
#import "Header.h"


#import "AViewController.h"
#import "BViewController.h"
#import "CViewController.h"
#import "DViewController.h"
#import "TeacherViewController.h"

#import "TaskTeachVC.h"
#import "NavigationVC.h"

@interface TabVC ()

@end

@implementation TabVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    if ([[ZYUserManager userInfo].type integerValue] == 2 ) {
        ((AppDelegate *)[UIApplication sharedApplication].delegate).teacher = YES;
    }else{
        ((AppDelegate *)[UIApplication sharedApplication].delegate).teacher = NO;
    }
    
    
    

    AViewController *ac = [[AViewController alloc]init];

    
    [self addChildController:ac
                       title:@"知博院"
                   imageName:@"首页-2@3x"
           selectedImageName:@"首页-3@3x"
                       navVc:[NavigationVC class]];
    
    NSLog(@"%d",Teacher);
    if (Teacher) {

        TaskTeachVC *bc = [[TaskTeachVC alloc]init];
        
        [self addChildController:bc
                           title:@"任务"
                       imageName:@"任务中心"
               selectedImageName:@"任务副本"
                           navVc:[UINavigationController class]];
        
    }else{
        BViewController *bc = [[BViewController alloc]init];
        
        [self addChildController:bc
                           title:@"任务"
                       imageName:@"任务中心"
               selectedImageName:@"任务副本"
                           navVc:[NavigationVC class]];
        
        
    }
    
    

    
     CViewController *cc = [[CViewController alloc]init];

    [self addChildController:cc
                       title:@"课程"
                   imageName:@"课程-3@3x"
           selectedImageName:@"课程-2@3x"
                       navVc:[NavigationVC class]];

    if (Teacher) {
        TeacherViewController *dc = [[TeacherViewController alloc]init];
        
        [self addChildController:dc
                           title:@"我的"
                       imageName:@"我的-4@3x"
               selectedImageName:@"我的-3@3x"
                           navVc:[NavigationVC class]];
    }else{
        DViewController *dc = [[DViewController alloc]init];
        [self addChildController:dc
                           title:@"我的"
                       imageName:@"我的-4@3x"
               selectedImageName:@"我的-3@3x"
                           navVc:[NavigationVC class]];
    }

    
    
    
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [Helper setMoRenTabBar:self];
}

- (void)addChildController:(UIViewController*)childController title:(NSString*)title imageName:(NSString*)imageName selectedImageName:(NSString*)selectedImageName navVc:(Class)navVc {
    NSLog(@"加载姿势图");
    childController.title = title;
    childController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage *selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    childController.tabBarItem.selectedImage =selectedImage;
    
    
    
    //    UIImage *image = [childController.tabBarItem.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //    childController.tabBarItem.selectedImage = image;
    //    childController.tabBarController.tabBar.tintColor = jiuYiQiColor2 ;
    // 设置一下选中tabbar文字颜色
    [childController.tabBarItem setTitleTextAttributes:@{ NSForegroundColorAttributeName : ZhuTiColor}
                                              forState:UIControlStateSelected];
    
    
    
//    [childController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
    
    NavigationVC * nav = [[navVc alloc] initWithRootViewController:childController];
    
    [self addChildViewController:nav];
}

#pragma mark - 屏幕方向控制
- (BOOL)shouldAutorotate{

    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{

    return UIInterfaceOrientationMaskPortrait;
}



//#pragma mark - 控制屏幕旋转方法
//- (BOOL)shouldAutorotate{
//    return [self.selectedViewController shouldAutorotate];
//}
//
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
//    return [self.selectedViewController supportedInterfaceOrientations];
//}
//
//- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
//    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
